package cn.demo.test

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object wordcount3 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("wordCount")
    val context = new SparkContext(conf)
    val  lines = context.textFile("D:\\IDE\\Workspace_IDE\\spark_study\\spark_core\\src\\main\\resources\\test.txt")
    val words =lines.flatMap(_.split(""))
    val wordTo0ne = words.map(word => (word,1))
    val value = wordTo0ne.reduceByKey(_ + _)
    val wordToCount:RDD[(String,Int)] = wordTo0ne.reduceByKey(_ + _)
    val  array = wordToCount.collect()
    array.foreach(println)
    context.stop()
  }

}
